'''
Created on 2009-11-7

@author: jazy
function handlers in pcap
'''

import ctypes
import pcap_c_types

pcap=ctypes.CDLL("libpcap.so")
# void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,const u_char *);
CALLBACK=ctypes.CFUNCTYPE(None,ctypes.c_char_p,ctypes.POINTER(pcap_c_types.pcap_pkthdr),ctypes.POINTER(ctypes.c_ubyte))
#
#char    *pcap_pcap_t    *pcap_create(const char *, char *);lookupdev(char *);
pcap_create=pcap.pcap_create
#int    pcap_activate(pcap_t *);
pcap_activate=pcap.pcap_activate
#int    pcap_set_timeout(pcap_t *, int);
pcap_set_timeout=pcap. pcap_set_timeout
#int    pcap_set_buffer_size(pcap_t *, int);
pcap_set_buffer_size=pcap.pcap_set_buffer_size
#int    pcap_can_set_rfmon(pcap_t *);
pcap_can_set_rfmon=pcap. pcap_can_set_rfmon
#int    pcap_set_rfmon(pcap_t *, int);
pcap_set_rfmon=pcap.pcap_set_rfmon
#int    pcap_set_snaplen(pcap_t *, int);
pcap_set_snaplen=pcap.pcap_set_snaplen
#int    pcap_set_promisc(pcap_t *, int);
pcap_set_promisc=pcap.pcap_set_promisc
pcap_lookupdev=pcap.pcap_lookupdev
pcap_lookupdev.restype=ctypes.c_char_p
#int    pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
pcap_lookupnet=pcap.pcap_lookupnet
#pcap_t    *pcap_open_live(const char *, int, int, int, char *);
pcap_open_live=pcap.pcap_open_live
#pcap_t    *pcap_open_dead(int, int);
pcap_open_dead=pcap.pcap_open_dead
#pcap_t    *pcap_open_offline(const char *, char *);
pcap_open_offline=pcap.pcap_open_offline
#pcap_t *pcap_fopen_offline(FILE *, char *);
pcap_fopen_offline=pcap.pcap_fopen_offline
#void    pcap_close(pcap_t *);
pcap_close=pcap.pcap_close
#int    pcap_loop(pcap_t *, int, pcap_handler, u_char *);
pcap_loop=pcap.pcap_loop
#int    pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
pcap_dispatch=pcap.pcap_dispatch
#const u_char* pcap_next(pcap_t *, struct pcap_pkthdr *);
pcap_next=pcap.pcap_next
#int     pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
pcap_next_ex=pcap.pcap_next_ex
#void    pcap_breakloop(pcap_t *);
pcap_breakloop=pcap.pcap_breakloop
#int    pcap_stats(pcap_t *, struct pcap_stat *);
pcap_stats=pcap.pcap_stats
#int    pcap_setfilter(pcap_t *, struct bpf_program *);
pcap_setfilter=pcap.pcap_setfilter
#int     pcap_setdirection(pcap_t *, pcap_direction_t);
pcap_setdirection=pcap.pcap_setdirection
#int    pcap_getnonblock(pcap_t *, char *);
pcap_getnonblock=pcap.pcap_getnonblock
#int    pcap_setnonblock(pcap_t *, int, char *);
pcap_setnonblock=pcap.pcap_setnonblock
#void    pcap_perror(pcap_t *, char *);
pcap_perror=pcap.pcap_perror
#int    pcap_inject(pcap_t *, const void *, size_t);
pcap_inject=pcap.pcap_inject
#int    pcap_sendpacket(pcap_t *, const u_char *, int);
pcap_sendpacket=pcap.pcap_sendpacket
#const char *pcap_strerror(int);
pcap_strerror=pcap.pcap_strerror
pcap_strerror.restype=ctypes.c_char_p
#const char *pcap_statustostr(int);
pcap_statustostr=pcap.pcap_statustostr
pcap_statustostr.restype=ctypes.c_char_p
#char    *pcap_geterr(pcap_t *);
pcap_geterr=pcap.pcap_geterr
pcap_geterr.restype=ctypes.c_char_p
#int    pcap_compile(pcap_t *, struct bpf_program *, const char *, int,bpf_u_int32);
pcap_compile=pcap.pcap_compile
#int    pcap_compile_nopcap(int, int, struct bpf_program *,const char *, int, bpf_u_int32);
pcap_compile_nopcap=pcap.pcap_compile_nopcap
#void    pcap_freecode(struct bpf_program *);
pcap_freecode=pcap.pcap_freecode
#int    pcap_datalink(pcap_t *);
pcap_datalink=pcap.pcap_datalink
#int    pcap_list_datalinks(pcap_t *, int **);
pcap_list_datalinks=pcap.pcap_list_datalinks
#int    pcap_set_datalink(pcap_t *, int);
pcap_set_datalink=pcap.pcap_set_datalink
#int    pcap_datalink_name_to_val(const char *);
pcap_datalink_name_to_val=pcap. pcap_datalink_name_to_val
#const char *pcap_datalink_val_to_name(int);
pcap_datalink_val_to_name=pcap.pcap_datalink_val_to_name
#const char *pcap_datalink_val_to_description(int);
pcap_datalink_val_to_description=pcap.pcap_datalink_val_to_description
#int    pcap_snapshot(pcap_t *);
pcap_snapshot=pcap.pcap_snapshot
#int    pcap_is_swapped(pcap_=t *);
pcap_is_swapped=pcap.pcap_is_swapped
#int    pcap_major_version(pcap_t *);
pcap_major_version=pcap. pcap_major_version
#int    pcap_minor_version(pcap_t *);
pcap_minor_version=pcap. pcap_minor_version
#FILE    *pcap_file(pcap_t *);
pcap_file=pcap.pcap_file
#int    pcap_fileno(pcap_t *);
pcap_fileno=pcap.pcap_fileno
#pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
pcap_dump_open=pcap.pcap_dump_open
#pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
pcap_dump_fopen=pcap.pcap_dump_fopen
#FILE    *pcap_dump_file(pcap_dumper_t *);
pcap_dump_file=pcap.pcap_dump_file
#long    pcap_dump_ftell(pcap_dumper_t *);
pcap_dump_ftell=pcap. pcap_dump_ftell
#int    pcap_dump_flush(pcap_dumper_t *);
pcap_dump_flush=pcap.pcap_dump_flush
#void    pcap_dump_close(pcap_dumper_t *);
pcap_dump_close=pcap. pcap_dump_close
#void    pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
pcap_dump=pcap.pcap_dump
#int    pcap_findalldevs(pcap_if_t **, char *);
pcap_findalldevs=pcap.pcap_findalldevs
#void    pcap_freealldevs(pcap_if_t *);
pcap_freealldevs=pcap.pcap_freealldevs
#typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,const u_char *);
#const char *pcap_lib_version(void);

pcap_lib_version=pcap.pcap_lib_version
pcap_lib_version.restype=ctypes.c_char_p
#int    pcap_get_selectable_fd(pcap_t *);
pcap_get_selectable_fd=pcap.pcap_get_selectable_fd
